<?php
class db_mysql {
	var $db;
    var $pre;
	function get($name) {
		switch($name){
			case 'InsertId':
				return mysql_insert_id(); break;
            case 'errormsg':
                return mysql_error(); break;
			default:
				return null;
		}
	}
	function call($name,$arguments) {
        if($name=='queryf'){
            return $this->call('query', array(call_user_func_array('sprintf', $arguments)));
        }
		if($name=='fetch_one'){
			return $this->call('fetch', array($this->call('query', $arguments)));
		}
        if($name=='query'){
            $arguments[0]=preg_replace('/\^/', $this->pre, $arguments[0], 1);
        }
		$Map=array(
			'query'=>'mysql_query',
			'fetch'=>'mysql_fetch_assoc',
			'result'=>'mysql_result'
		);
		return call_user_func_array($Map[$name], $arguments);
	}
	function Initialize($host, $user, $pass, $base, $pre) {
		$db=mysql_connect($host, $user, $pass, 0);
		@mysql_select_db($base, $db);
		$this->db=$db;
        $this->pre=$pre;
		$this->call('query', array('SET character_set_connection=utf8, character_set_results=utf8, character_set_client=binary'));
	}
}